{extend name="layout" /}
{block name="body"}
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <ul class="nav nav-tabs page-tabs pt-2 pl-3 pr-3">
                <li class="nav-item"> <a href="{:url('system/email')}" class="nav-link">邮箱配置</a> </li>
                <li class="nav-item"> <a href="{:url('system/phone')}" class="nav-link active">验证码配置</a> </li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active">
                    <div class="edit-form">
                        <div class="form-group">
                            <label for="accessKeyId">AccessKey ID</label>
                            <input type="hidden" class="form-control" id="typename" value="phone">
                            <input type="text" class="form-control" id="accessKeyId" value="{$phone.accessKeyId}" placeholder="请输入AccessKey ID">
                        </div>
                        <div class="form-group">
                            <label for="accessKeySecret">AccessKey Secret</label>
                            <input type="text" class="form-control" id="accessKeySecret" value="{$phone.accessKeySecret}" placeholder="请输入AccessKey Secret">
                        </div>
                        <div class="form-group">
                            <label for="SignName">短信签名名称</label>
                            <input type="text" class="form-control" id="SignName" value="{$phone.SignName}" placeholder="请输入短信签名名称">
                        </div>
                        <div class="form-group">
                            <label for="TemplateCode">短信模板CODE</label>
                            <input type="text" class="form-control" id="TemplateCode" value="{$phone.TemplateCode}" placeholder="请输入短信模板CODE">
                        </div>
                        <div class="form-group">
                            <label for="TemplateParam">短信模板变量值</label>
                            <input type="text" class="form-control" id="TemplateParam" value="{$phone.TemplateParam}" placeholder="请输入短信模板变量值">
                        </div>
                        <div class="form-group">
                            <label for="PhoneNumbers">测试手机号</label>
                            <input type="phone" class="form-control" id="PhoneNumbers" placeholder="请输入测试手机号">
                        </div>
                        <button type="button" onclick="updatephone()" class="btn btn-w-sm btn-primary mb-2">保存</button>
                        <button type="button" class="btn btn-w-sm btn-info mb-2" onclick="TestPhone()">测 试</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="js"}
<script>
    function updatephone() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var typename = $.trim($("#typename").val());
        var accessKeyId = $.trim($("#accessKeyId").val());
        var accessKeySecret = $.trim($("#accessKeySecret").val());
        var SignName = $.trim($("#SignName").val());
        var TemplateCode = $.trim($("#TemplateCode").val());
        var TemplateParam = $.trim($("#TemplateParam").val());
        $.ajax({
            type: "POST",
            url: "{:url('system/phone')}",
            data: {
                typename: typename,
                accessKeyId: accessKeyId,
                accessKeySecret: accessKeySecret,
                SignName: SignName,
                TemplateCode: TemplateCode,
                TemplateParam: TemplateParam
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }

    function TestPhone() {
        var l = $('body').lyearloading({
            opacity: 0.2,
            spinnerSize: 'lg',
            spinnerText: '后台处理中，请稍后...',
            textColorClass: 'text-info',
            spinnerColorClass: 'text-info'
        });
        var PhoneNumbers = $.trim($("#PhoneNumbers").val());
        if (PhoneNumbers == "" || PhoneNumbers == null) {
            l.destroy();
            notify.error("请输入测试手机号");
            return false;
        }
        $.ajax({
            type: "POST",
            url: "{:url('system/TestPhone')}",
            data: {
                PhoneNumbers: PhoneNumbers
            },
            dataType: "json",
            success: function (data) {
                setTimeout(function () {
                    l.destroy();
                }, 1e3)
                if (data.code == 1) {
                    notify.success(data.msg);
                } else {
                    notify.error(data.msg);
                }
            },
            error: function () {
                l.destroy();
                notify.error("系统错误");
            }
        })
    }
</script>
{/block}